1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Calendar; 26 27 private import glib.ConstructionException; 28 private import glib.DateTime; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Widget; 32 private import gtk.c.functions; 33 public import gtk.c.types; 34 private import std.algorithm; 35 36 37 /** 38 * `GtkCalendar` is a widget that displays a Gregorian calendar, one month 39 * at a time. 40 * 41 *  42 * 43 * A `GtkCalendar` can be created with [ctor@Gtk.Calendar.new]. 44 * 45 * The date that is currently displayed can be altered with 46 * [method@Gtk.Calendar.select_day]. 47 * 48 * To place a visual marker on a particular day, use 49 * [method@Gtk.Calendar.mark_day] and to remove the marker, 50 * [method@Gtk.Calendar.unmark_day]. Alternative, all 51 * marks can be cleared with [method@Gtk.Calendar.clear_marks]. 52 * 53 * The selected date can be retrieved from a `GtkCalendar` using 54 * [method@Gtk.Calendar.get_date]. 55 * 56 * Users should be aware that, although the Gregorian calendar is the 57 * legal calendar in most countries, it was adopted progressively 58 * between 1582 and 1929. Display before these dates is likely to be 59 * historically incorrect. 60 * 61 * # CSS nodes 62 * 63 * ``` 64 * calendar.view 65 * ├── header 66 * │ ├── button 67 * │ ├── stack.month 68 * │ ├── button 69 * │ ├── button 70 * │ ├── label.year 71 * │ ╰── button 72 * ╰── grid 73 * ╰── label[.day-name][.week-number][.day-number][.other-month][.today] 74 * ``` 75 * 76 * `GtkCalendar` has a main node with name calendar. It contains a subnode 77 * called header containing the widgets for switching between years and months. 78 * 79 * The grid subnode contains all day labels, including week numbers on the left 80 * (marked with the .week-number css class) and day names on top (marked with the 81 * .day-name css class). 82 * 83 * Day labels that belong to the previous or next month get the .other-month 84 * style class. The label of the current day get the .today style class. 85 * 86 * Marked day labels get the :selected state assigned. 87 */ 88 public class Calendar : Widget 89 { 90 /** the main Gtk struct */ 91 protected GtkCalendar* gtkCalendar; 92 93 /** Get the main Gtk struct */ 94 public GtkCalendar* getCalendarStruct(bool transferOwnership = false) 95 { 96 if (transferOwnership) 97 ownedRef = false; 98 return gtkCalendar; 99 } 100 101 /** the main Gtk struct as a void* */ 102 protected override void* getStruct() 103 { 104 return cast(void*)gtkCalendar; 105 } 106 107 /** 108 * Sets our main struct and passes it to the parent class. 109 */ 110 public this (GtkCalendar* gtkCalendar, bool ownedRef = false) 111 { 112 this.gtkCalendar = gtkCalendar; 113 super(cast(GtkWidget*)gtkCalendar, ownedRef); 114 } 115 116 117 /** */ 118 public static GType getType() 119 { 120 return gtk_calendar_get_type(); 121 } 122 123 /** 124 * Creates a new calendar, with the current date being selected. 125 * 126 * Returns: a newly `GtkCalendar` widget 127 * 128 * Throws: ConstructionException GTK+ fails to create the object. 129 */ 130 public this() 131 { 132 auto __p = gtk_calendar_new(); 133 134 if(__p is null) 135 { 136 throw new ConstructionException("null returned by new"); 137 } 138 139 this(cast(GtkCalendar*) __p); 140 } 141 142 /** 143 * Remove all visual markers. 144 */ 145 public void clearMarks() 146 { 147 gtk_calendar_clear_marks(gtkCalendar); 148 } 149 150 /** 151 * Returns a `GDateTime` representing the shown 152 * year, month and the selected day. 153 * 154 * The returned date is in the local time zone. 155 * 156 * Returns: the `GDate` representing the shown date 157 */ 158 public DateTime getDate() 159 { 160 auto __p = gtk_calendar_get_date(gtkCalendar); 161 162 if(__p is null) 163 { 164 return null; 165 } 166 167 return new DateTime(cast(GDateTime*) __p, true); 168 } 169 170 /** 171 * Returns if the @day of the @calendar is already marked. 172 * 173 * Params: 174 * day = the day number between 1 and 31. 175 * 176 * Returns: whether the day is marked. 177 */ 178 public bool getDayIsMarked(uint day) 179 { 180 return gtk_calendar_get_day_is_marked(gtkCalendar, day) != 0; 181 } 182 183 /** 184 * Returns whether @self is currently showing the names 185 * of the week days. 186 * 187 * This is the value of the [property@Gtk.Calendar:show-day-names] 188 * property. 189 * 190 * Returns: Whether the calendar shows day names. 191 */ 192 public bool getShowDayNames() 193 { 194 return gtk_calendar_get_show_day_names(gtkCalendar) != 0; 195 } 196 197 /** 198 * Returns whether @self is currently showing the heading. 199 * 200 * This is the value of the [property@Gtk.Calendar:show-heading] 201 * property. 202 * 203 * Returns: Whether the calendar is showing a heading. 204 */ 205 public bool getShowHeading() 206 { 207 return gtk_calendar_get_show_heading(gtkCalendar) != 0; 208 } 209 210 /** 211 * Returns whether @self is showing week numbers right 212 * now. 213 * 214 * This is the value of the [property@Gtk.Calendar:show-week-numbers] 215 * property. 216 * 217 * Returns: Whether the calendar is showing week numbers. 218 */ 219 public bool getShowWeekNumbers() 220 { 221 return gtk_calendar_get_show_week_numbers(gtkCalendar) != 0; 222 } 223 224 /** 225 * Places a visual marker on a particular day. 226 * 227 * Params: 228 * day = the day number to mark between 1 and 31. 229 */ 230 public void markDay(uint day) 231 { 232 gtk_calendar_mark_day(gtkCalendar, day); 233 } 234 235 /** 236 * Switches to @date's year and month and select its day. 237 * 238 * Params: 239 * date = a `GDateTime` representing the day to select 240 */ 241 public void selectDay(DateTime date) 242 { 243 gtk_calendar_select_day(gtkCalendar, (date is null) ? null : date.getDateTimeStruct()); 244 } 245 246 /** 247 * Sets whether the calendar shows day names. 248 * 249 * Params: 250 * value = Whether to show day names above the day numbers 251 */ 252 public void setShowDayNames(bool value) 253 { 254 gtk_calendar_set_show_day_names(gtkCalendar, value); 255 } 256 257 /** 258 * Sets whether the calendar should show a heading. 259 * 260 * The heading contains the current year and month as well as 261 * buttons for changing both. 262 * 263 * Params: 264 * value = Whether to show the heading in the calendar 265 */ 266 public void setShowHeading(bool value) 267 { 268 gtk_calendar_set_show_heading(gtkCalendar, value); 269 } 270 271 /** 272 * Sets whether week numbers are shown in the calendar. 273 * 274 * Params: 275 * value = whether to show week numbers on the left of the days 276 */ 277 public void setShowWeekNumbers(bool value) 278 { 279 gtk_calendar_set_show_week_numbers(gtkCalendar, value); 280 } 281 282 /** 283 * Removes the visual marker from a particular day. 284 * 285 * Params: 286 * day = the day number to unmark between 1 and 31. 287 */ 288 public void unmarkDay(uint day) 289 { 290 gtk_calendar_unmark_day(gtkCalendar, day); 291 } 292 293 /** 294 * Emitted when the user selects a day. 295 */ 296 gulong addOnDaySelected(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 297 { 298 return Signals.connect(this, "day-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED); 299 } 300 301 /** 302 * Emitted when the user switched to the next month. 303 */ 304 gulong addOnNextMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 305 { 306 return Signals.connect(this, "next-month", dlg, connectFlags ^ ConnectFlags.SWAPPED); 307 } 308 309 /** 310 * Emitted when user switched to the next year. 311 */ 312 gulong addOnNextYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 313 { 314 return Signals.connect(this, "next-year", dlg, connectFlags ^ ConnectFlags.SWAPPED); 315 } 316 317 /** 318 * Emitted when the user switched to the previous month. 319 */ 320 gulong addOnPrevMonth(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 321 { 322 return Signals.connect(this, "prev-month", dlg, connectFlags ^ ConnectFlags.SWAPPED); 323 } 324 325 /** 326 * Emitted when user switched to the previous year. 327 */ 328 gulong addOnPrevYear(void delegate(Calendar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 329 { 330 return Signals.connect(this, "prev-year", dlg, connectFlags ^ ConnectFlags.SWAPPED); 331 } 332 }